﻿using System.Data;

namespace LibMS.Models
{
    public class UnitOfWork
    {
        private IDbConnection _dbConnection;

        private IRepository<LibBorrowDocument> _libBorrowDocument;
        private IRepository<LibCategories> _libCategories;
        private IRepository<LibDocuments> _libDocuments;
        private IRepository<LibRack> _libRack;
        private IRepository<LibReader> _libReader;
        private IRepository<LibUploadData> _libUploadData;
        private IRepository<CmsUser> _cmsUser;
        private IRepository<LibRole> _libRole;
        private IRepository<LibUserRole> _libUserRole;

        public UnitOfWork()
        {
            _dbConnection = MSSqlConnection.GetConnection();
        }

        public IRepository<LibBorrowDocument> LibBorrowDocument
        {
            get
            {
                if (_libBorrowDocument == null)
                {
                    _libBorrowDocument = new Repository<LibBorrowDocument>(_dbConnection, StringConstant.TABLE_LIBBORROWDOCUMENT);
                }
                return _libBorrowDocument;
            }
        }
        public IRepository<LibCategories> LibCategories
        {
            get
            {
                if (_libCategories == null)
                {
                    _libCategories = new Repository<LibCategories>(_dbConnection, StringConstant.TABLE_LIBCATEGORIES);
                }
                return _libCategories;
            }
        }
        public IRepository<LibDocuments> LibDocuments
        {
            get
            {
                if (_libDocuments == null)
                {
                    _libDocuments = new Repository<LibDocuments>(_dbConnection, StringConstant.TABLE_LIBDOCUMENTS);
                }
                return _libDocuments;
            }
        }
        public IRepository<LibRack> LibRack
        {
            get
            {
                if (_libRack == null)
                {
                    _libRack = new Repository<LibRack>(_dbConnection, StringConstant.TABLE_LIBRACK);
                }
                return _libRack;
            }
        }
        public IRepository<LibReader> LibReader
        {
            get
            {
                if (_libReader == null)
                {
                    _libReader = new Repository<LibReader>(_dbConnection, StringConstant.TABLE_LIBREADER);
                }
                return _libReader;
            }
        }
        public IRepository<LibUploadData> LibUploadData
        {
            get
            {
                if (_libUploadData == null)
                {
                    _libUploadData = new Repository<LibUploadData>(_dbConnection, StringConstant.TABLE_LIBUPLOADDATA);
                }
                return _libUploadData;
            }
        }
        public IRepository<CmsUser> CmsUser
        {
            get
            {
                if (_cmsUser == null)
                {
                    _cmsUser = new Repository<CmsUser>(_dbConnection, StringConstant.TABLE_CMSUSER);
                }
                return _cmsUser;
            }
        }
        public IRepository<LibRole> LibRole
        {
            get
            {
                if (_libRole == null)
                {
                    _libRole = new Repository<LibRole>(_dbConnection, StringConstant.TABLE_LIBROLE);
                }
                return _libRole;
            }
        }
        public IRepository<LibUserRole> LibUserRole
        {
            get
            {
                if (_libUserRole == null)
                {
                    _libUserRole = new Repository<LibUserRole>(_dbConnection, StringConstant.TABLE_LIBUSERROLE);
                }
                return _libUserRole;
            }
        }
    }
}